{include file="pageheader"}
<div class="container-fluid" style="padding:0">
	<div class="row" style="margin:0">
	    <tr>			
                        <td><div style="float:right" class="navbar-form ">
                                <a href="{url('add')}"><button class="btn btn-primary">添加频道</button></a>
				</div></td>
		</tr>
            <div class="container-fluid" style="padding:0">
	<div class="row" style="margin:0">
	  <div class="col-md-12 col-sm-12 col-lg-12" style="padding:0;">
		<div class="panel panel-default">
			<table class="table table-hover" class="list-div" id="list-table">
                <tr style="background:#f8f8f8">
                    <th class="text-center">频道名称</th>
                    <th class="text-center">是否显示</th>
                    <th class="text-center">上级频道</th>
                    <th class="text-center">排序</th>
                    <th class="text-center">操作</th>
                </tr>
      {loop $cat_info $cat}
    <tr align="center" class="0" id="0_4">
    <td align="left" width="15%" class="first-cell">
            <img src="__ASSETS__/images/menu_plus.gif" id="icon_0_4" width="9" height="9" border="0" style="margin-left:0em" onclick="rowClicked(this)">
            <span style="color:#222;font-size:12px;font-weight:bold;">{$cat[name]}</span>
        </td>
   
    <td width="10%"><img src="__ASSETS__/images/{if $cat[status] ==1}yes{else}no{/if}.gif" /></td>
						    <td width="10%">
						                 顶级频道
						            </td>
						    <td width="10%" align="center"><span onclick="listTable.edit(this, 'edit_sort_order', 1)">{$cat[sort_order]}</span></td>
						    <td width="24%" align="center">
						         <a href="{url('add', array('id'=>$cat['id']))}">编辑</a> |
						     <a href="javascript:if(confirm('{$lang['confirm_delete']}')){window.location.href='{url('del', array('id'=>$cat[id]))}'};">删除</a>
						    </td>
    </td>
  </tr>
   {loop $cat[cat_id] $val}
    <tr align="center" class="1" id="1_10" style="display:none">
    <td align="left" class="first-cell">
            <img src="__ASSETS__/images/menu_minus.gif" id="icon_1_10" width="9" height="9" border="0" style="margin-left:1em" onclick="rowClicked(this)">
            <span style="color:#555;font-weight:bold;">{$val[name]}</span>
        </td>
    
  <td width="10%"><img src="__ASSETS__/images/{if $val[status] ==1}yes{else}no{/if}.gif" /></td>
			    <td width="10%">
			                 二级频道
			            </td>
			    <td width="10%" align="center"><span onclick="listTable.edit(this, 'edit_sort_order', 1)">{$val[sort_order]}</span></td>
			    <td width="24%" align="center">
			         <a href="{url('add', array('id'=>$val['id']))}">编辑</a> |
			      <a href="javascript:if(confirm('{$lang['confirm_delete']}')){window.location.href='{url('del', array('id'=>$val[id]))}'};">删除</a>
			    </td>
  </tr>
           {/loop}
      {/loop}
   
		</table>
		</div>
	  </div>
	</div>
</div>
	</div>
    {include file="pageview"}
 </div>
</div>
{include file="pagefooter"}

<script>
/**
 * 折叠分类列表
 */
var imgPlus = new Image();
imgPlus.src = "__ASSETS__/images/menu_plus.gif";

function rowClicked(obj)
{
   // 当前图像
  img = obj;
  // 取得上二级tr>td>img对象
  obj = obj.parentNode.parentNode;
  // 整个分类列表表格
  var tbl = document.getElementById("list-table");
  // 当前分类级别
  var lvl = parseInt(obj.className);
  // 是否找到元素
  var fnd = false;
  var sub_display = img.src.indexOf('menu_minus.gif') > 0 ? 'none' : (Browser.isIE) ? 'block' : 'table-row' ;
  // 遍历所有的分类
  for (i = 0; i < tbl.rows.length; i++)
  {
      var row = tbl.rows[i];
      if (row == obj)
      {
          // 找到当前行
          fnd = true;
          //document.getElementById('result').innerHTML += 'Find row at ' + i +"<br/>";
      }
      else
      {
          if (fnd == true)
          {
              var cur = parseInt(row.className);
              var icon = 'icon_' + row.id;
              if (cur > lvl)
              {
                  row.style.display = sub_display;
                  if (sub_display != 'none')
                  {
                      var iconimg = document.getElementById(icon);
                      iconimg.src = iconimg.src.replace('plus.gif', 'minus.gif');
                  }
              }
              else
              {
                  fnd = false;
                  break;
              }
          }
      }
  }

  for (i = 0; i < obj.cells[0].childNodes.length; i++)
  {
      var imgObj = obj.cells[0].childNodes[i];
      if (imgObj.tagName == "IMG" && imgObj.src != 'images/menu_arrow.gif')
      {
          imgObj.src = (imgObj.src == imgPlus.src) ? '__ASSETS__/images/menu_minus.gif' : imgPlus.src;
      }
  }
}
	</script>
